package com.atguigu.tingshu.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author atguigu-mqx
 * @ClassName ThreadPoolExecutorConfig
 * @description: TODO
 * @date 2023年10月28日
 * @version: 1.0
 */
@Configuration
public class ThreadPoolExecutorConfig {

    /**
     * 自定义线程池：不能使用工具类创建线程池 oom!
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                8, //  核心线程 io 2n cpu n+1
                16,
                3,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10)
        );
    }
}
